package ar.uba.is2.common.utils;

/**
 * This Util class intend to offer services related to the interaction with hibernate persistence layer
 * 
 * @author Alex Valencia
 */
import org.hibernate.HibernateException;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.classic.Session;

public class HibernateUtil {

    private static final SessionFactory sessionFactory;

    static {
        try {
        	// Si no ponemos fichero, intenta cargar "/hibernate.cfg.xml" en el raiz
            sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
        } catch (Throwable ex) {
            // Log exception!
            throw new ExceptionInInitializerError(ex);
        }
    }

    public static Session getSession() throws HibernateException {
        return sessionFactory.openSession();
    }
}
